// pages/shanyueLookfor/shanyueLookfor.js
import {$init, $digest} from '../../lib/page.data'
import {$login, $request, Session} from '../../lib/page.auth'

const {regeneratorRuntime} = global
//获取应用实例
let api = require('../../utils/api.js');
let http = require('../../utils/http.js');
const app = getApp()

Page({

    /**
     * 页面的初始数据
     */
    data: {
        online_totle:0,
        domain:api.oss_domain,
        beauty: [],
        timeLong: 1,
        onloadShow: true,
      opunit: api.opunit,
    },
    lookDetail: function (e) {
        let id = e.currentTarget.dataset.id;
        wx.navigateTo({
            url: '/pages/indexBuy/indexBuy?id=' + id,
        })
    },
    //获取匹配玩家
    async getMatcher() {
        var res = await $request({
          url: api.new_price_list,
            method: 'POST',
            data: {
                gender: this.data.gender,
                sid: this.data.sid,
                type: 'distance',
            }
        });
        return res;
    },
  buyNow: function (e) {
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/indexBuyOrder/indexBuyOrder?pid=' + id,
    })
  },
  toBuyTap: function (e) {
    let id = e.currentTarget.dataset.id;
    // let uid = e.currentTarget.dataset.uid;
    wx.navigateTo({
      url: '/pages/indexBuy/indexBuy?id=' + id
    })
  },
    /**
     * 生命周期函数--监听页面加载
     */
    async onLoad(options) 
    {
      
      var user = wx.getStorageSync('user_info');
        this.setData({
            'gender': options.gender,
            'sid': options.sid
        });

        var that = this;
        var token = wx.getStorageSync('token');
        var lat = wx.getStorageSync('latitude');
        var lon = wx.getStorageSync('longitude');
        var data = {
            gender: this.data.gender,
            sid: this.data.sid,
            type: 'distance',
            lat: lat,
            lon: lon,
            user_id: user.data.id
        }
      http.get(api.new_price_list, data, function(res)
        {
            console.log(res.data)
            var skillPriceList = res.data.data;
            if (res.data.code == 1) 
            {
                that.setData({
                    beauty: skillPriceList,
                    online_totle: skillPriceList.length
                });
            }
        }, "请求中...");

        // console.log(options);
        // $init(this);

        // this.setData({
        //     'gender': options.gender,
        //     'sid': options.sid
        // });

        // try {
        //     var res = await this.getMatcher();
        //     var skillPriceList = JSON.parse(res.data);
        //     console.log(skillPriceList);
        //     this.setData({
        //         'beauty': skillPriceList,
        //     })
        // } catch (e) {
        //     console.log('##########error2:', e);
        // }
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {
        var that = this;
        var timeLong = this.data.timeLong;
        var timer = setInterval(function () {
            timeLong--;
            if (timeLong == 0) {
                that.setData({
                    onloadShow: false
                });
                clearInterval(timer);
            }
        }, 1000)

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        console.log(3)
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {
        console.log(4)
    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})